package GIUmk2;

import java.awt.CardLayout;
import java.awt.Container;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JPanel;



public class SidePanel extends Container {
	
	/**
	 * Allows serialization.
	 */
	private static final long serialVersionUID = 5564406377170362856L;
	
	private Container user_buttons;
	private Container author_buttons;
	private Container reviewer_buttons;
	private Container subprogram_buttons;
	private Container program_buttons;
	
	private CardLayout my_layout;
	
	private final FullFrame my_frame;	
	
	protected static final String[] BUTTON_ROLES = {"user", "author", "reviewer", "subprogram", "program"};
	
	/**
	 * The full list of buttons.
	 */
	private final ArrayList<Button2> BUTTON_GROUPS;
	
	protected SidePanel(final FullFrame frame) {
		super();
		my_frame = frame;
		this.BUTTON_GROUPS = new ArrayList<>();
		my_layout = new CardLayout(10,10);
		populateButtons();
		mapButtons();
		this.setLayout(my_layout);
		this.add(user_buttons, SidePanel.BUTTON_ROLES[0]);
		this.add(author_buttons, SidePanel.BUTTON_ROLES[1]);
		this.add(reviewer_buttons, SidePanel.BUTTON_ROLES[2]);
		this.add(subprogram_buttons, SidePanel.BUTTON_ROLES[3]);
		this.add(program_buttons, SidePanel.BUTTON_ROLES[4]);
		this.setVisible(true);
	}
	
	protected void updateButtons(final int role) {
		my_layout.show(this, SidePanel.BUTTON_ROLES[role]);
	}
	
	/**
	 * Creates a generic bucket of buttons for switching roles.
	 */
	private void populateButtons() {
		this.BUTTON_GROUPS.add(new Button2("Login"));
		this.BUTTON_GROUPS.add(new Button2("Submit"));
		this.BUTTON_GROUPS.add(new Button2("Get Review"));
		this.BUTTON_GROUPS.add(new Button2("Edit Submission"));
		this.BUTTON_GROUPS.add(new Button2("Assign Paper"));
		this.BUTTON_GROUPS.add(new Button2("Accept Submission"));
		this.BUTTON_GROUPS.add(new Button2("Designate SubProgram Chairs"));
		this.BUTTON_GROUPS.add(new Button2("View Status"));
		this.BUTTON_GROUPS.add(new Button2("View Assignments"));
		
		for(int i = 0; i < this.BUTTON_GROUPS.size(); i++) {
			// TODO: attach actions here, pass frame to buttons in order to observe them.
			this.BUTTON_GROUPS.get(i).setPattern(my_frame);
		}
	}
	
	private void mapButtons() {
		user_buttons = new Container();
		author_buttons = new Container();
		reviewer_buttons = new Container();
		subprogram_buttons = new Container();
		program_buttons = new Container();
		
		user_buttons.setLayout(new BoxLayout(user_buttons, BoxLayout.Y_AXIS));
		author_buttons.setLayout(new BoxLayout(author_buttons, BoxLayout.Y_AXIS));
		reviewer_buttons.setLayout(new BoxLayout(reviewer_buttons, BoxLayout.Y_AXIS));
		subprogram_buttons.setLayout(new BoxLayout(subprogram_buttons, BoxLayout.Y_AXIS));
		program_buttons.setLayout(new BoxLayout(program_buttons, BoxLayout.Y_AXIS));
		
		
		user_buttons.add(this.BUTTON_GROUPS.get(0));
		
		author_buttons.add(this.BUTTON_GROUPS.get(0));
		author_buttons.add(this.BUTTON_GROUPS.get(1));
		author_buttons.add(this.BUTTON_GROUPS.get(2));
		author_buttons.add(this.BUTTON_GROUPS.get(3));
		
		reviewer_buttons.add(this.BUTTON_GROUPS.get(0));
		reviewer_buttons.add(this.BUTTON_GROUPS.get(1));
		
		subprogram_buttons.add(this.BUTTON_GROUPS.get(0));
		subprogram_buttons.add(this.BUTTON_GROUPS.get(1));
		subprogram_buttons.add(this.BUTTON_GROUPS.get(4));
		
		program_buttons.add(this.BUTTON_GROUPS.get(0));
		program_buttons.add(this.BUTTON_GROUPS.get(5));
		program_buttons.add(this.BUTTON_GROUPS.get(6));
		program_buttons.add(this.BUTTON_GROUPS.get(7));
		program_buttons.add(this.BUTTON_GROUPS.get(8));
	}

}
